// router全局配置，如有必要可分文件抽离 intelligence
import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layouts'
//import EmptyLayout from '@/layouts/EmptyLayout'
import {
  publicPath,
  routerMode
} from '@/config'

Vue.use(VueRouter)

export const constantRoutes = [
  //登录页面
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },
  //401 页面
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/401'),
    hidden: true,
  },
  //404 页面
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    hidden: true,
  },
  //申请入驻页面
  {
    path: '/cooperate',
    name: 'cooperate',
    component: () => import('@/views/cooperate/cooperate'),
    hidden: true
  },
  {
    path: '/commonlyUsed',
    component: Layout,
    alwaysShow: false,
     hidden: true,
    children: [{
      path: 'commonlyUsed',
      name: 'CommonlyUsed',
      component: () => import('@/views/commonlyUsed/index'),
      meta: {
        title: '快捷操作',
        noKeepAlive: true,
      },
    }],
  },

  // {
  //   path: '/selfbuild/activity',
  //   component: Layout,
  //   meta: {
  //     title: '活动管理',
  //     permissions: ["admin", "user"]
  //   },
  //   name: '活动管理',
  //   alwaysShow: false,
  //   children: [

  //   {
  //     path: 'trylearn',
  //     name: 'Trylearn',
  //     hidden: true,
  //     component: () => import('@/views/discountsmanage/trylearn'),
  //     meta: {
  //       title: '免费试学',
  //       noKeepAlive: true,
  //       breadcrumb: true,
  //       permissions: ['admin']
  //     },
  //   },
  //   {
  //     path: 'recommend',
  //     name: 'Recommend',
  //     hidden: true,
  //     component: () => import('@/views/discountsmanage/recommend'),
  //     meta: {
  //       title: '推荐好友',
  //       noKeepAlive: true,
  //       breadcrumb: true,
  //       permissions: ['admin']
  //     },
  //   },
  //   {
  //     path: 'signUpLuckyDraw',
  //     name: 'SignUpLuckyDraw',
  //     hidden: true,
  //     component: () => import('@/views/discountsmanage/signUpLuckyDraw'),
  //     meta: {
  //       title: '报名抽奖',
  //       noKeepAlive: true,
  //       breadcrumb: true,
  //       permissions: ['admin']
  //     },
  //   },
  //   {
  //     path: 'reduced',
  //     name: 'Reduced',
  //     hidden: true,
  //     component: () => import('@/views/discountsmanage/reduced'),
  //     meta: {
  //       title: '报名立减',
  //       noKeepAlive: true,
  //       breadcrumb: true,
  //       permissions: ['admin']
  //     },
  //   },
  //   {
  //     path: 'preparation',
  //     name: 'Preparation',
  //     hidden: true,
  //     component: () => import('@/views/discountsmanage/preparation'),
  //     meta: {
  //       title: '资料准备',
  //       noKeepAlive: true,
  //       breadcrumb: true,
  //       permissions: ['admin']
  //     },
  //   },
  //   {
  //     path: 'hostingService',
  //     name: 'HostingService',
  //     hidden: true,
  //     component: () => import('@/views/discountsmanage/hostingService'),
  //     meta: {
  //       title: '客服托管',
  //       noKeepAlive: true,
  //       breadcrumb: true,
  //       permissions: ['admin']
  //     },
  //   }
  //   ],
  // },
]

/*当settings.js里authentication配置的是intelligence时，views引入交给前端配置*/

export const asyncRoutes = [
/*
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    alwaysShow: false,
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: {
        title: '工作台',
        remixIcon: 'icon-1',
        noKeepAlive: true,
        permissions: ["admin", "user", "normal"]
      },
    }],
  },

  {
    path: '/intentionstudent',
    component: Layout,
    name: '意向学员',
    meta: {
      title: '意向学员',
      remixIcon: 'icon8'
    },
    gurpName: '学员',
    alwaysShow: false,
    children: [{
      path: 'intentionstudent',
      name: 'Intentionstudent',
      component: () => import('@/views/intentionstudent/index'),
      meta: {

        title: '意向学员',
        noKeepAlive: true,
        breadcrumb: false,
        remixIcon: 'icon8'
      },
    }]
  },
  // {
  //   path: '/intentionstudent',
  //   component: Layout,
  //   name: '意向学员',
  //   meta: {
  //     title: '意向学员',
  //     remixIcon: 'icon8'
  //   },
  //    gurpName: '学员',
  //   alwaysShow: false,
  //   children: [{
  //     path: 'intentionstudent',
  //     name: 'Intentionstudent',
  //     component: () => import('@/views/intentionstudent/index'),
  //     meta: {

  //       title: '意向学员',
  //       noKeepAlive: true,
  //       breadcrumb: false,
  //       remixIcon: 'icon8'
  //     },
  //   }]
  // },
  {
    path: '/studentist',
    component: Layout,
    meta: {
      title: '学员列表',
      permissions: ["admin", "user"]
    },
    name: '学员列表',
    alwaysShow: false,
    children: [{
      path: 'studentlist',
      name: 'studentlist',
      component: () => import('@/views/studentlist/index'),
      meta: {
        title: '学员列表',
        remixIcon: 'xylb',
        noKeepAlive: true,
        permissions: ["admin", "user"]
      },
    }],
  },

  {
    path: '/documentmanage',
    component: Layout,
    meta: {
      title: '建档管理',
      permissions: ["admin", "user"]
    },
    name: '建档管理',
    alwaysShow: false,
    children: [{
      path: 'documentmanage',
      name: 'Documentmanage',
      component: () => import('@/views/documentmanage/index'),
      meta: {
        title: '建档管理',
        remixIcon: 'dagl',
        noKeepAlive: true,
        permissions: ["admin", "user"]
      },
    }],
  },
  {
    path: '/scoremanage',
    component: Layout,
    meta: {
      title: '成绩管理',
      permissions: ["admin", "user"]
    },
    name: '成绩管理',
    alwaysShow: false,
    children: [{
      path: 'scoremanage',
      name: 'Scoremanage',
      component: () => import('@/views/scoremanage/index'),
      meta: {
        title: '成绩管理',
        remixIcon: 'cjgl',
        noKeepAlive: true,
        permissions: ["admin", "user"]
      },
    }],
  },
  {
    path: '/subscribemanage',
    component: Layout,
    meta: {
      title: '约考管理',
      permissions: ["admin", "user"]
    },
    name: '约考管理',
    alwaysShow: false,
    children: [{
      path: 'subscribemanage',
      name: 'Subscribemanage',
      component: () => import('@/views/subscribemanage/index'),
      meta: {
        title: '约考管理',
        remixIcon: 'ykgl',
        noKeepAlive: true,
        permissions: ["admin", "user"]
      },
    }],
  },
  {
    path: '/selfbuild',
    component: Layout,
    name: '自建平台',
    gurpName: '运营',
    meta: {
      title: '自建平台',
      remixIcon: 'icon15',
      permissions: ['admin']
    },
    alwaysShow: true,
    children: [{
        path: 'baseinfo',
        name: 'Baseinfo',
        component: () => import('@/views/selfbuild/baseinfo'),
        meta: {
          title: '基本信息',
          noKeepAlive: true,
          breadcrumb: true,
          permissions: ['admin']
        },
      },
      // {
      //   path: 'activity',
      //   name: 'Activity',
      //   component: () => import('@/views/selfbuild/activity'),
      //   meta: {
      //     title: '平台活动',
      //     noKeepAlive: true,
      //     breadcrumb: true,
      //     permissions: ['admin']
      //   },
      // },
      {
        path: 'jointllist',
        name: 'Jointllist',
        component: () => import('@/views/jointmanagement/jointllist'),
        meta: {
          title: '联营管理',
          noKeepAlive: true,
          breadcrumb: true,
          permissions: ['admin']
        },
      }
    ]
  },
  {
    path: '/selfbuild/activity',
    component: Layout,
    meta: {
      title: '活动管理',
      permissions: ["admin", "user"]
    },
    name: '活动管理',
    alwaysShow: false,
    children: [{
        path: 'activity',
        name: 'Activity',
        component: () => import('@/views/selfbuild/activity'),
        meta: {
          title: '活动管理',
          remixIcon: 'hdgl',
          noKeepAlive: true,
          permissions: ["admin", "user"]
        },
      },
      {
        path: 'trylearn',
        name: 'Trylearn',
        hidden: true,
        component: () => import('@/views/discountsmanage/trylearn'),
        meta: {
          title: '免费试学',
          noKeepAlive: true,
          breadcrumb: true,
          permissions: ['admin']
        },
      },
      {
        path: 'recommend',
        name: 'Recommend',
        hidden: true,
        component: () => import('@/views/discountsmanage/recommend'),
        meta: {
          title: '推荐好友',
          noKeepAlive: true,
          breadcrumb: true,
          permissions: ['admin']
        },
      },
      {
        path: 'signUpLuckyDraw',
        name: 'SignUpLuckyDraw',
        hidden: true,
        component: () => import('@/views/discountsmanage/signUpLuckyDraw'),
        meta: {
          title: '报名抽奖',
          noKeepAlive: true,
          breadcrumb: true,
          permissions: ['admin']
        },
      },
      {
        path: 'reduced',
        name: 'Reduced',
        hidden: true,
        component: () => import('@/views/discountsmanage/reduced'),
        meta: {
          title: '报名立减',
          noKeepAlive: true,
          breadcrumb: true,
          permissions: ['admin']
        },
      },
      {
        path: 'preparation',
        name: 'Preparation',
        hidden: true,
        component: () => import('@/views/discountsmanage/preparation'),
        meta: {
          title: '资料准备',
          noKeepAlive: true,
          breadcrumb: true,
          permissions: ['admin']
        },
      },
      {
        path: 'hostingService',
        name: 'HostingService',
        hidden: true,
        component: () => import('@/views/discountsmanage/hostingService'),
        meta: {
          title: '客服托管',
          noKeepAlive: true,
          breadcrumb: true,
          permissions: ['admin']
        },
      }
    ],
  },

  {
    path: '/discountsmanage',
    component: Layout,
    meta: {
      title: '优惠管理',
      permissions: ["admin"]
    },
    name: '优惠管理',
    alwaysShow: false,
    children: [{
        path: 'coupon',
        name: 'Coupon',
        component: () => import('@/views/discountsmanage/coupon'),
        meta: {
          title: '优惠管理',
          remixIcon: 'icon16',
          noKeepAlive: true,
          permissions: ["admin"]
        },
      },

    ],
  },

  {
    path: '/calsstypemanage',
    component: Layout,
    name: '班型管理',
    meta: {
      title: '班型管理',
      remixIcon: 'icon6',
      permissions: ['admin', 'user']
    },
    alwaysShow: false,
    children: [{
      path: 'classtype',
      name: 'Classtype',
      component: () => import('@/views/calsstypemanage/classtype'),
      meta: {
        title: '班型管理',
        noKeepAlive: true,
        breadcrumb: false,
        remixIcon: 'icon6'
      },
    }]
  },
  {
    path: '/commentmanage',
    component: Layout,
    name: '评价管理',
    meta: {
      title: '评价管理',
      remixIcon: 'icon7',
      permissions: ['admin']
    },
    alwaysShow: false,
    children: [{
      path: 'commentlist',
      name: 'Commentlist',
      component: () => import('@/views/commentmanage/commentList'),
      meta: {
        title: '评价管理',
        noKeepAlive: true,
        breadcrumb: false,
        remixIcon: 'icon7'
      },
    }]
  },

  {
    path: '/finance',
    component: Layout,
    name: '学员费用',
    gurpName: '财务',
    meta: {
      title: '学员费用',
      remixIcon: 'icon-3',
      permissions: ['admin']
    },
    alwaysShow: true,
    children: [{
        path: 'incomemanage',
        name: 'Incomemanage',
        component: () => import('@/views/finance/incomemanage'),
        meta: {
          title: '收入管理',
          noKeepAlive: true,
          permissions: ['admin']
        },
      },
      {
        path: 'expendituremanage',
        name: 'Expendituremanage',
        component: () => import('@/views/finance/expendituremanage'),
        meta: {
          title: '支出管理',
          noKeepAlive: true
        },
      }
    ]
  },
  {
    path: '/drivingauth',
    component: Layout,
    gurpName: '驾校',
    meta: {
      title: '驾校信息',
      permissions: ["admin", "user"]
    },
    name: 'Drivingauth',
    alwaysShow: false,
    children: [{
      path: 'schoolauth',
      name: 'Schoolauth',
      component: () => import('@/views/drivingauth'),
      meta: {
        title: '驾校信息',
        remixIcon: 'jxgl',
        noKeepAlive: true,
        permissions: ["admin", "user"]
      },
    }],
  },
  {
    path: '/organizationmanage',
    component: Layout,
    name: '机构管理',
    meta: {
      title: '机构管理',
      remixIcon: 'icon2',
      permissions: ["admin", "user"]
    },
    children: [

      // {
      //   path: 'branchschool',
      //   name: 'Branchschool',
      //   component: () => import('@/views/organizationmanage/branchschool'),
      //   meta: {
      //     title: '校区',
      //     noKeepAlive: true,
      //     permissions: ["admin"]
      //   },
      // },
      // {
      //   path: 'assigns',
      //   name: 'Assigns',
      //   component: () => import('@/views/organizationmanage/assigns'),
      //   meta: {
      //     title: '报名点',
      //     noKeepAlive: true
      //   },
      // },
      {
        path: 'registrationAgency',
        name: 'RegistrationAgency',
        component: () => import('@/views/organizationmanage/registrationAgency'),
        meta: {
          title: '运营机构',
          noKeepAlive: true
        },
      },
      {
        path: 'training',
        name: 'Training',
        component: () => import('@/views/organizationmanage/training'),
        meta: {
          title: '训练场地',
          noKeepAlive: true
        },
      },
      {
        path: 'examination',
        name: 'Examination',
        component: () => import('@/views/organizationmanage/examination'),
        meta: {
          title: '考试场地',
          noKeepAlive: true
        },
      }
    ]
  },
  {
    path: '/organization',
    component: Layout,
    name: '组织管理',
    meta: {
      title: '组织管理',
      remixIcon: 'icon3',
      gurpName: '驾校'
    },
    alwaysShow: true,
    children: [{
      path: 'coachinfo',
      name: 'Coachinfo',
      component: () => import('@/views/organization/coachinfo'),
      meta: {
        title: '教练信息',
        noKeepAlive: true
      },
    }]
  },
  {
    path: '/car',
    component: Layout,
    name: '车辆管理',
    meta: {
      title: '车辆管理',
      remixIcon: 'icon-2'
    },
    alwaysShow: true,
    children: [{
      path: 'carList',
      name: 'CarList',
      component: () => import('@/views/car/carList'),
      meta: {
        title: '车辆列表',
        noKeepAlive: true
      },
    }]
  },
  {
    path: '/baseset',
    component: Layout,
    name: '基础设置',
    meta: {
      title: '基础设置',
      remixIcon: 'icon4'
    },
    alwaysShow: true,
    children: [{
      path: 'account-manage',
      name: 'Account-manage',
      component: () => import('@/views/base/accountmanage'),
      meta: {
        title: '账户管理',
        noKeepAlive: true
      },
    }, ]
  },



  {
    path: '*',
    redirect: '/404',
    hidden: true,
  }, */


]

const router = new VueRouter({
  base: publicPath,
  mode: routerMode,
  scrollBehavior: () => ({
    y: 0,
  }),
  routes: constantRoutes,
})
//注释的地方是允许路由重复点击，如果你觉得框架路由跳转规范太过严格可选择放开
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch((err) => err)
}


export function resetRouter() {
  router.matcher = new VueRouter({
    base: publicPath,
    mode: routerMode,
    scrollBehavior: () => ({
      y: 0,
    }),
    routes: constantRoutes,
  }).matcher
}

export default router
